# EnCoding:UTF-8
# Date: 2023-5-18
# Author: Chen Yihao(陈一豪)
# Student ID: 2021110884
# Class: 2103102

class State:
    """Describe current status of the problem"""

    def __init__(self, pos_monkey="A", pos_box="B", pos_banana="C", on_box=False):
        """Init the state"""
        self.pos_monkey = pos_monkey
        self.pos_box = pos_box
        self.pos_banana = pos_banana
        self.on_box = on_box
        self.get_banana = False

    def at_pos(self, thing, pos):
        """If the thing is at the pos"""
        if thing == "monkey":
            return self.pos_monkey == pos
        elif thing == "box":
            return self.pos_box == pos
        elif thing == "banana":
            return self.pos_banana == pos

    def run(self):
        """Run the problem"""
        i = 0
        while not self.get_banana:
            i += 1
            # Monkey on the box
            if self.on_box:
                if self.pos_monkey == self.pos_banana:
                    print(f"step{i}: Monkey get the banana!")
                    self.get_banana = True
                    break
                else:
                    print(f"Step{i}: Monkey get off the box.")
                    self.on_box = False
            # Monkey not on the box
            else:
                if self.pos_monkey == self.pos_box and self.pos_box != self.pos_banana:
                    print(
                        f"Step{i}: Monkey move the box to {self.pos_banana} for the banana.")
                    self.pos_box = self.pos_banana
                    self.pos_monkey = self.pos_banana
                elif self.pos_monkey == self.pos_box:
                    print(f"Step{i}: Monkey get on the box.")
                    self.on_box = True
                else:
                    print(f"Step{i}: Monkey goto {self.pos_box} for the box.")
                    self.pos_monkey = self.pos_box


if __name__ == "__main__":
    print("Hello, Little Monkey! Let's get the banana together.")

    # Input
    pos_monkey = input("Please Input the position of monkey: ")
    pos_box = input("Please Input the position of box: ")
    pos_banana = input("Please Input the position of banana: ")
    on = input("Please Input whether the monkey is on the box(Y/N): ")
    if pos_monkey == pos_box and on == "Y":
        on_box = True
    else:
        on_box = False

    # Init the state
    state = State(pos_monkey, pos_box, pos_banana, on_box)

    # Run the problem
    state.run()
